package com.suyun.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.fastjson.JSON;
import com.suyun.domain.Order;
import com.suyun.domain.Product;
import com.suyun.service.OrderService;
import com.suyun.service.ProductService;
import com.suyun.service.impl.OrderServiceImpl2;
import com.suyun.service.impl.OrderServiceImpl3;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@Slf4j
public class OrdertController3 {

    @Autowired
    private OrderServiceImpl2 orderServiceImpl2;

    @Autowired
    private OrderServiceImpl3 orderServiceImpl3;


    int i=0;

    @RequestMapping("order/message1")
    public String message1() {
        //模拟链路调用
        /*orderServiceImpl2.message();*/
        i++;
        if(i % 3 ==0){
            throw  new RuntimeException();
        }
        return "测试高并发1";
    }

    @RequestMapping("order/message2")
    public String message2() {
        /*orderServiceImpl2.message();*/
        return "测试高并发2";
    }

    @RequestMapping("order/message3")
    @SentinelResource("message3")
    public String message3(String name,Integer age) {

        return "测试高并发3"+name+age;
    }

    @RequestMapping("order/message")
    public String message() {
        return orderServiceImpl3.message("suyun");
    }
}
